home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Environments / PowerMacOberon feb96 / Source / DirElems.Mod (.txt) < prev    next >
Encoding:
Oberon Text  |  1995-12-04  |  3.5 KB  |  102 lines  |  [TEXT/.Ob4]

  1. Syntax10.Scn.Fnt
  2. StampElems
  3. Alloc
  4. 4 Dec 95
  5. Syntax10b.Scn.Fnt
  6. MODULE DirElems;    (** HM 
  7.  (mah auto-update)*)
  8. IMPORT Viewers, Texts, TextFrames, Oberon, PopupElems, Directories, Display;
  9.     Elem* = POINTER TO ElemDesc;
  10.     ElemDesc* = RECORD (PopupElems.ElemDesc)
  11.     END;
  12.     NotifyMsg = RECORD(Display.FrameMsg) END;
  13.     Frame = POINTER TO RECORD(Display.FrameDesc) elem: Elem END;
  14.     oldDirNotify: Directories.Notifier;
  15.     curDirName: ARRAY 32 OF CHAR;
  16. PROCEDURE ReadName (t: Texts.Text; pos: LONGINT; VAR name: ARRAY OF CHAR);
  17.     VAR r: Texts.Reader; ch, stopch: CHAR; i: INTEGER; beg, end, time: LONGINT;
  18. BEGIN
  19.     Texts.OpenReader(r, t, pos); Texts.Read(r, ch); i := 0;
  20.     IF ch = '"' THEN Texts.Read(r, ch);
  21.         WHILE ~r.eot & (ch # '"') DO name[i] := ch; INC(i); Texts.Read(r, ch) END
  22.     ELSE
  23.         WHILE ~r.eot & (ch > " ") DO name[i] := ch; INC(i); Texts.Read(r, ch) END
  24.     END;
  25.     name[i] := 0X;
  26.     IF name = "^" THEN
  27.         Oberon.GetSelection(t, beg, end, time);
  28.         IF time >= 0 THEN ReadName(t, beg, name) END
  29. END ReadName;
  30. PROCEDURE SetDirName;
  31.     VAR i, j: INTEGER; name: ARRAY 256 OF CHAR; d, d0: Directories.Directory;
  32. BEGIN
  33.     d := Directories.Current(); d0 := Directories.Startup();
  34.     i := 0; WHILE (d0.path[i] # 0X) & (CAP(d0.path[i]) = CAP(d.path[i])) DO INC(i) END;
  35.     IF (d0.path[i] = 0X) & ((d.path[i] = 0X) OR (d.path[i] = Directories.delimiter)) THEN
  36.         IF d.path[i] = Directories.delimiter THEN
  37.             name[0] := "$"; j := 0; INC (i);
  38.             REPEAT INC(j); name[j] := d.path[i]; INC(i) UNTIL name[j] = 0X
  39.         ELSE name := "$"
  40.         END
  41.     ELSE
  42.         COPY(d.path, name)
  43.     END;
  44.     i := 0; WHILE name[i] # 0X DO INC(i) END;
  45.     IF i < 32 THEN COPY(name, curDirName)
  46.     ELSE curDirName[31] := 0X; j := 31;
  47.         REPEAT DEC(i); DEC(j); curDirName[j] := name[i] UNTIL j = 1;
  48.         curDirName[0] := "*"
  49. END SetDirName;
  50. PROCEDURE Exec (e: Elem; pos: LONGINT);
  51.     VAR msg: NotifyMsg; name: ARRAY 256 OF CHAR;
  52. BEGIN ReadName(e.menu, pos, name); Directories.Change(name)
  53. END Exec;
  54. PROCEDURE DirNotify (op: INTEGER; path, name: ARRAY OF CHAR);
  55. VAR msg: NotifyMsg;
  56. BEGIN
  57.     IF op = Directories.change THEN SetDirName; Viewers.Broadcast (msg) END;
  58.     oldDirNotify (op, path, name)
  59. END DirNotify;
  60. PROCEDURE HandleFrame(f: Display.Frame; VAR msg: Display.FrameMsg);
  61.     VAR m: TextFrames.UpdateMsg;
  62. BEGIN
  63.     IF msg IS NotifyMsg THEN
  64.         WITH f: Frame DO
  65.             TextFrames.NotifyDisplay (Texts.ElemBase(f.elem), TextFrames.replace, Texts.ElemPos(f.elem), Texts.ElemPos(f.elem)+1)
  66.         END
  67. END HandleFrame;
  68. PROCEDURE Handle* (e: Texts.Elem; VAR m: Texts.ElemMsg);
  69.     VAR e1: Elem; f: Frame;
  70. BEGIN
  71.     WITH e: Elem DO
  72.         COPY (curDirName, e.name);
  73.         WITH m: Texts.CopyMsg DO NEW(e1); m.e := e1; PopupElems.Handle(e, m)
  74.         |  m: Texts.IdentifyMsg DO m.mod := "DirElems"; m.proc := "Alloc"
  75.         |  m: PopupElems.ExecMsg DO Exec(e, m.pos)
  76.         |  m: TextFrames.DisplayMsg DO
  77.             IF ~m.prepare THEN
  78.                 NEW (f); f.X := m.X0; f.Y := m.Y0; f.W := 1; f.H := 1;    (* trick (c) mah/cs *)
  79.                 f.handle := HandleFrame; f.elem := e;
  80.                 m.elemFrame := f
  81.             END;
  82.             PopupElems.Handle (e, m)
  83.         ELSE PopupElems.Handle(e, m)
  84.         END
  85. END Handle;
  86. PROCEDURE Alloc*;
  87.     VAR e: Elem;
  88. BEGIN
  89.     NEW(e); e.handle := Handle; Texts.new := e
  90. END Alloc;
  91. PROCEDURE Insert*;
  92.     VAR e: Elem; insert: TextFrames.InsertElemMsg;
  93. BEGIN
  94.     NEW(e); e.handle := Handle; e.small := FALSE;
  95.     e.menu := TextFrames.Text(""); PopupElems.MeasureMenu(e);
  96.     insert.e := e; Viewers.Broadcast(insert)
  97. END Insert;
  98. BEGIN
  99.     SetDirName;
  100.     oldDirNotify := Directories.notify; Directories.notify := DirNotify
  101. END DirElems.
  102.